home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / Hyperion / src / plat_hpux.c < prev    next >
C/C++ Source or Header  |  1997-02-26  |  5KB  |  299 lines

  1. /*
  2.  * @(#)plat_hpux.c    1.7    12/28/93
  3.  *
  4.  * HP/UX-specific drive control routines.
  5.  */
  6. static char *ident = "@(#)plat_hpux.c    1.7 12/28/93";
  7.  
  8. #ifdef hpux
  9.  
  10. #include <errno.h>
  11. #include <stdio.h>
  12. #include <sys/types.h>
  13. #include <fcntl.h>
  14. #include <sys/param.h>
  15. #include <sys/stat.h>
  16. #include <sys/time.h>
  17. #include <sys/scsi.h>
  18. #include <ustat.h>
  19.  
  20. #include "struct.h"
  21.  
  22. #define    DEFAULT_CD_DEVICE    "/dev/rscsi"
  23.  
  24. void *malloc();
  25. char *strchr();
  26.  
  27. int    min_volume = 0;
  28. int    max_volume = 255;
  29.  
  30. extern char    *cd_device;
  31.  
  32. /*
  33.  * Initialize the drive.  A no-op for the generic driver.
  34.  */
  35. int
  36. gen_init(d)
  37.     struct wm_drive    *d;
  38. {
  39.     return (0);
  40. }
  41.  
  42. /*
  43.  * Get the number of tracks on the CD.
  44.  */
  45. int
  46. gen_get_trackcount(d, tracks)
  47.     struct wm_drive    *d;
  48.     int        *tracks;
  49. {
  50.     return (wm_scsi2_get_trackcount(d, tracks));
  51. }
  52.  
  53. /*
  54.  * Get the start time and mode (data or audio) of a track.
  55.  */
  56. int
  57. gen_get_trackinfo(d, track, data, startframe)
  58.     struct wm_drive    *d;
  59.     int        track, *data, *startframe;
  60. {
  61.     return (wm_scsi2_get_trackinfo(d, track, data, startframe));
  62. }
  63.  
  64. /*
  65.  * Get the number of frames on the CD.
  66.  */
  67. int
  68. gen_get_cdlen(d, frames)
  69.     struct wm_drive    *d;
  70.     int        *frames;
  71. {
  72.     int        tmp;
  73.  
  74.     return (wm_scsi2_get_cdlen(d, frames));
  75. }
  76.  
  77. /*
  78.  * Get the current status of the drive: the current play mode, the absolute
  79.  * position from start of disc (in frames), and the current track and index
  80.  * numbers if the CD is playing or paused.
  81.  */
  82. int
  83. gen_get_drive_status(d, oldmode, mode, pos, track, index)
  84.     struct wm_drive    *d;
  85.     enum cd_modes    oldmode, *mode;
  86.     int        *pos, *track, *index;
  87. {
  88.     return (wm_scsi2_get_drive_status(d, oldmode, mode, pos, track, index));
  89. }
  90.  
  91. /*
  92.  * Set the volume level for the left and right channels.  Their values
  93.  * range from 0 to 100.
  94.  */
  95. int
  96. gen_set_volume(d, left, right)
  97.     struct wm_drive    *d;
  98.     int        left, right;
  99. {
  100.     return (wm_scsi2_set_volume(d, left, right));
  101. }
  102.  
  103. /*
  104.  * Read the initial volume from the drive, if available.  Each channel
  105.  * ranges from 0 to 100, with -1 indicating data not available.
  106.  */
  107. int
  108. gen_get_volume(d, left, right)
  109.     struct wm_drive    *d;
  110.     int        *left, *right;
  111. {
  112.     return (wm_scsi2_get_volume(d, left, right));
  113. }
  114.  
  115. /*
  116.  * Pause the CD.
  117.  */
  118. int
  119. gen_pause(d)
  120.     struct wm_drive    *d;
  121. {
  122.     return (wm_scsi2_pause(d));
  123. }
  124.  
  125. /*
  126.  * Resume playing the CD (assuming it was paused.)
  127.  */
  128. int
  129. gen_resume(d)
  130.     struct wm_drive    *d;
  131. {
  132.     return (wm_scsi2_resume(d));
  133. }
  134.  
  135. /*
  136.  * Stop the CD.
  137.  */
  138. int
  139. gen_stop(d)
  140.     struct wm_drive    *d;
  141. {
  142.     return (wm_scsi2_stop(d));
  143. }
  144.  
  145. /*
  146.  * Play the CD from one position to another (both in frames.)
  147.  */
  148. int
  149. gen_play(d, start, end)
  150.     struct wm_drive    *d;
  151.     int        start, end;
  152. {
  153.     return (wm_scsi2_play(d, start, end));
  154. }
  155.  
  156. /*
  157.  * Eject the current CD, if there is one.
  158.  */
  159. int
  160. gen_eject(d)
  161.     struct wm_drive    *d;
  162. {
  163.     struct stat    stbuf;
  164.     struct ustat    ust;
  165.  
  166.     if (fstat(d->fd, &stbuf) != 0)
  167.         return (-2);
  168.  
  169.     /* Is this a mounted filesystem? */
  170.     if (ustat(stbuf.st_rdev, &ust) == 0)
  171.         return (-3);
  172.  
  173.     return (wm_scsi2_eject(d));
  174. }
  175.  
  176. /*
  177.  * Send a SCSI command out the bus.
  178.  */
  179. int
  180. wm_scsi(d, cdb, cdblen, retbuf, retbuflen, getreply)
  181.     struct wm_drive    *d;
  182.     unsigned char    *cdb;
  183.     int        cdblen;
  184.     void        *retbuf;
  185.     int        retbuflen;
  186.     int        getreply;
  187. {
  188. #ifdef SIOC_IO
  189.     struct sctl_io        cmd;
  190.  
  191.     memset(&cmd, 0, sizeof(cmd));
  192.     cmd.cdb_length = cdblen;
  193.     cmd.data = retbuf;
  194.     cmd.data_length = retbuflen;
  195.     cmd.max_msecs = 1000;
  196.     cmd.flags = getreply ? SCTL_READ : 0;
  197.     memcpy(cmd.cdb, cdb, cdblen);
  198.  
  199.     return (ioctl(d->fd, SIOC_IO, &cmd));
  200. #else
  201.     /* this code, for pre-9.0, is BROKEN!  ugh. */
  202.     char            reply_buf[12];
  203.     struct scsi_cmd_parms    cmd;
  204.  
  205.     memset(&cmd, 0, sizeof(cmd));
  206.     cmd.clock_ticks = 500;
  207.     cmd.cmd_mode = 1;
  208.     cmd.cmd_type = cdblen;
  209.     memcpy(cmd.command, cdb, cdblen);
  210.     if (ioctl(d->fd, SIOC_SET_CMD, &cmd) < 0)
  211.         return (-1);
  212.     if (getreply)
  213.     {
  214.         if (read(d->fd, retbuf, retbuflen) < 0)
  215.             return (-1);
  216.     }
  217.     else
  218.         (void) read(d->fd, reply_buf, sizeof(reply_buf));
  219.  
  220.     return (0);
  221. #endif
  222. }
  223.  
  224. /*
  225.  * Open the CD and figure out which kind of drive is attached.
  226.  */
  227. int
  228. wmcd_open(d)
  229.     struct wm_drive    *d;
  230. {
  231.     int        fd, flag = 1;
  232.     static int    warned = 0;
  233.     char        vendor[9], model[17], rev[5];
  234.  
  235.     if (d->fd >= 0)        /* Device already open? */
  236.         return (0);
  237.     
  238.     if (cd_device == NULL)
  239.         cd_device = DEFAULT_CD_DEVICE;
  240.  
  241.     d->fd = open(cd_device, O_RDWR);
  242.     if (d->fd < 0)
  243.     {
  244.         if (errno == EACCES)
  245.         {
  246.             if (! warned)
  247.             {
  248.                 fprintf(stderr,
  249.         "As root, please run\n\nchmod 666 %s\n\n%s\n", cd_device,
  250.         "to give yourself permission to access the CD-ROM device.");
  251.                 warned++;
  252.             }
  253.         }
  254.         else if (errno != EINTR)
  255.         {
  256.             perror(cd_device);
  257.             exit(1);
  258.         }
  259.  
  260.         /* No CD in drive. */
  261.         return (1);
  262.     }
  263.  
  264.     /* Prepare the device to receive raw SCSI commands. */
  265.     if (ioctl(d->fd, SIOC_CMD_MODE, &flag) < 0)
  266.     {
  267.         fprintf(stderr, "%s: SIOC_CMD_MODE: true: %s\n",
  268.             cd_device, strerror(errno));
  269.         /*exit(1);*/
  270.     }
  271.  
  272.     if (warned)
  273.     {
  274.         warned = 0;
  275.         fprintf(stderr, "Thank you.\n");
  276.     }
  277.  
  278.     /* Now fill in the relevant parts of the wm_drive structure. */
  279.     fd = d->fd;
  280.  
  281.     /* Default drive is the HP one, which might not respond to INQUIRY */
  282.     strcpy(vendor, "TOSHIBA");
  283.     strcpy(model, "XM-3301");
  284.     rev[0] = '\0';
  285.     wm_scsi_get_drive_type(d, vendor, model, rev);
  286.     *d = *(find_drive_struct(vendor, model, rev));
  287.     about_set_drivetype(d->vendor, d->model, rev);
  288.     d->fd = fd;
  289.  
  290.     (d->init)(d);
  291.  
  292.     return (0);
  293. }
  294.  
  295. void
  296. keep_cd_open() { }
  297.  
  298. #endif
  299.